<%@ page import="com.conversationboard.config.*" %>
<%@ page import="com.conversationboard.view.*" %>
<%@ page import="com.conversationboard.model.*" %>
<%@ page import="com.conversationboard.mobile.MobileDevice"%>

<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>

<!-- The RESTful API will throw up this page if you've not logged in and are authorising a protected
     resource; need to make it return something more appropriate, like an XML response saying
     you aren't authorised. -->

<%
	/* If there is a user ID and password cookie, then get it and populate the dialog */
	
	Cookie[] cookies = request.getCookies();
	
	String userName = "";
	String password = "";

	if (cookies != null) {
		for (Cookie cookie : cookies) {
			if (cookie.getName().equalsIgnoreCase("username")) {
				userName = cookie.getValue();
				break;
			}
		}
	
		for (Cookie cookie : cookies) {
			if (cookie.getName().equalsIgnoreCase("password")) {
				password = cookie.getValue();
				break;
			}
		}
	}
	
	boolean mobileDevice = MobileDevice.isMobileDevice(request);
	
%>

<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>Login Page</title>
	<link rel="stylesheet" type="text/css" href="<%=Configuration.getInstance().getRoot()%>/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>">
</head>


<% if (mobileDevice) { %>

<!-- Simplified, larger page for mobile devices -->

<body style="font-family: sans-serif; font-size: 200%">

	<form action="LoginControllerServlet" method="post">
	 	
	 	<label for="username">User Name (email address):</label>
	 	<input name="username" style="font-size: 100%; width: 100%" class="smalltextbox" type="text" size=100 value="<%= userName %>" />
	 	<br />
	 	<label for="password">Password:</label>
	 	<input name="password" style="font-size: 100%; width: 100%" class="smalltextbox" type="password" size=100 value="<%= password %>" />

		<label for="rememberMeCheckBox">Remember Me</label>
		<input type="checkbox" name="rememberMeCheckBox" value="true" />
		
	 	<input style="font-size: 100%" type="submit" value="Login" />
	</form>	
</body>

<% return; } %>


<body>

	<%= MainMenu.display(request.getUserPrincipal()) %>

	<div class="headingblock">
		<h1><%=Configuration.getInstance().getSiteName()%></h1>
	</div>

	<div class="mainblock">

		<h3>You are not logged in, please log in</h3>
		
		<p>You can change your password on the preferences page, once you're logged in.</p>
	
			<form class="formsection" action="<%= Configuration.getInstance().getRoot() %>/LoginControllerServlet" method="post">
			 	
			 	<label for="username">User Name (email address):</label><br />
			 	<input name="username" class="smalltextbox" type="text" size=100 value="<%= userName %>" /><br /><br />
			 	<label for="password">Password:</label>
			 	<br />
			 	<input name="password" class="smalltextbox" type="password" size=100 value="<%= password %>" /><br />

				<label for="rememberMeCheckBox">Remember Me</label>
				<input type="checkbox" name="rememberMeCheckBox" value="true" />

				<p>Please note that checking the 'Remember Me' box will store your username and password on your computer.</p>

				<br />
			 	<input type="submit" value="Login" />

				<p><a href='<%=Configuration.getInstance().getRoot()%>/Pages/register.jsp'>I haven't yet registered</a></p>
				<p><a href='<%=Configuration.getInstance().getRoot()%>/Pages/forgottenpassword.jsp'>I've Forgotten my Password</a></p>
			 	
			</form>	
		
		
		<br />
	</div>
	
	<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
	<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 

</body>

</html>
